<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/views/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/views/include/nocachehead.jsp"%>
<title>管理日志分类</title>
</head>
<body>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/stringutil.js"></script>
<script type="text/javascript">

function modifyCategory(id){
	var categoryTr=document.getElementById("categoryTr"+id);
	categoryTr.style.display = "none";
	var categoryForm=document.getElementById("categoryFormTr"+id);
	categoryForm.style.display = "";
	return false;
}
function modifyCategoryExecute(id){
	var categoryForm=document.getElementById("categoryForm"+id);
	var categoryName=document.getElementById("categoryName"+id);
	/*categoryName.value=categoryName.value.replaceAll("<","&lt;");
	categoryName.value=categoryName.value.replaceAll(">","&gt;");
	categoryName.value=categoryName.value.replaceAll("/","&frasl;");*/
	categoryName.value=categoryName.value.clean();
	if(categoryName.value == ""){
		alert("你让我为难了，输入点东西吧！");
		return false;
	}
	else if(categoryName.value.length>120){
		alert("你让我为难了，输入得太多了点吧，最多也就120字啊！");
	 	return false;
	}
	else{
		categoryForm.submit();
		return true;
	}
}
function cancelModify(id){
	var categoryTr=document.getElementById("categoryTr"+id);
	categoryTr.style.display = "";
	var categoryForm=document.getElementById("categoryFormTr"+id);
	categoryForm.style.display = "none";
	return false;
}
function addCategory()
{
	var addCategoryForm=document.getElementById("addCategoryForm");
	var addCategoryName=document.getElementById("addCategoryName");
	addCategoryName.value=addCategoryName.value.clean();
	if(addCategoryName.value == ""){
		alert("你让我为难了，输入点东西吧！");
		return false;
	}
	else if(addCategoryName.value.length>40){
		alert("你让我为难了，输入得太多了点吧，最多也就40字啊！");
	 	return false;
	}
	else{
		addCategoryForm.submit();
		return true;
	}
}

/*function getAuthorityOption(authority){
	//alert(authority);
	if(authority=='0') return "公开";
	//else if(authority=='5') return "仅同城";
	else if(authority=='10') return "仅粉丝";
	else return "仅自己";
}*/

</script>
<style type="text/css">
#categoryList {
	border-collapse: collapse;
	border: solid #999;
	border-width: 1px 1px 1px 1px;
	font-size: 14px;
}

#categoryList th,#categoryList td {
	border: solid #999;
	border-width: 0 0px 1px 0;
	padding: 0px;
	height: 28px
}
#newCategory {
	border-collapse: collapse;
	border: solid #999;
	border-width: 1px 1px 1px 1px;
	font-size: 14px;
}

#newCategory th,#newCategory td {
	border: solid #999;
	border-width: 0 0px 1px 0;
	padding: 0px;
	height: 28px
}
</style>

<%@ include file="/views/include/statusbar.jsp"%>

<br>
已有的分类:<br>
<br>
<c:set var="categories" scope="page" value="${requestScope.CATEGORIES}"/>
<table id="categoryList">
	<tr bgcolor="#0088dd" >
		<td width="240px">&nbsp;&nbsp; <b><font color="white">分类名称</font></b></td>
		<td width="100px"><b><font color="white">日志数</font></b></td>
		<!-- <td width="100px"><b><font color="white">权限</font></b></td> -->
		<td width="80px"></td>
		<td width="80px"></td>
	</tr>
	<c:forEach var="category" items="${categories}">
		<tr id="categoryTr${category.id}">
			<td>&nbsp;&nbsp;${category.categoryName}</td>
			<td>${category.articleNum}</td>
			<c:choose>
				<c:when test="${category.activity!='UNDELETABLE'}">
					<!-- <td>
					<c:choose>
						<c:when test="${category.authority==0}">公开</c:when>
						<c:when test="${category.authority==5}">仅同城</c:when>
						<c:when test="${category.authority==10}">仅粉丝</c:when>
						<c:when test="${category.authority==20}">仅自己</c:when>
					</c:choose>
					</td> -->
					<td><a href="#"onclick="javascript:modifyCategory(${category.id})">修改</a></td>
					<td><a href="<%=request.getContextPath()%>/article/category/delete/${category.id}.html" onclick="return confirm('你确定删除此日志分类么?\n\n提示:删除分类不会删除该分类下的日志');">删除</a></td>
				</c:when>
				<c:otherwise>
					<!-- <td>公开</td>-->
					<td></td>
					<td></td>
				</c:otherwise>
			</c:choose>
		</tr>
		<tr id="categoryFormTr${category.id}"  style="display:none" bgcolor="#eeccaa">
			<td colspan="5">
				<form id="categoryForm${category.id}" action="<%=request.getContextPath()%>/article/category/modify.html" method="post">
					<input type="hidden" name="id" value="${category.id}">
					<input type="text" name="categoryName" id="categoryName${category.id}" value="${category.categoryName}" size="48"> 
					<!-- <select name="authority" id="authority">
					
						<option value="0" <c:if test="${category.authority==0}">selected="selected"</c:if>>公开</option>
						<!-- <option value="5" <c:if test="${category.authority==5}">selected="selected"</c:if>>仅同城</option> -->
						<!-- <option value="10" <c:if test="${category.authority==10}">selected="selected"</c:if>>仅粉丝</option>
						<option value="20"  <c:if test="${category.authority==20}">selected="selected"</c:if>>仅自己</option>
					<!-- 
						<option value="${category.authority}" ><script type="text/javascript">getAuthorityOption(${category.authority})</script></option>
						<option value="0" >公开</option>
						<option value="5">仅同城</option>
						<option value="10">仅粉丝</option>
						<option value="20">仅自己</option>
						-->
					<!-- </select>-->
					<input type="button" onclick="modifyCategoryExecute(${category.id})"value="提交" />
					<input type="button" onclick="cancelModify(${category.id})" value="取消" />
				</form>
			</td>
		</tr>
	</c:forEach>
</table>
<br>
<form id="addCategoryForm" action="<%=request.getContextPath()%>/article/category/add.html"
	method="POST">
<table id="newCategory">
	<tr bgcolor="#cccccc">
		<td colspan="3">&nbsp;&nbsp;添加新分类</td>
	</tr>
	<tr>
		<td width="80px">&nbsp;&nbsp;分类名称:</td>
		<td><input type="text" name="categoryName" id="addCategoryName"
			size="32" /></td>
		<!-- <td width="40px">权限:</td>
		<td><select name="authority" id="addAuthority">
			<option value="0" >公开</option>
			<!-- <option value="5">仅同城</option> -->
			<!-- <option value="10">仅粉丝</option>
			<option value="20" >仅自己</option>
		</select></td>-->
		<td width="80px"><input type="button"  onclick="addCategory()" value="提交" /></td>
	</tr>
</table>
</form>
</body>
</html>